//
//  SDTableViewHeaderItemButton.m
//  SDHeaderView
//
//  Created by apple on 15/11/18.
//  Copyright © 2015年 MDJ. All rights reserved.
//

#import "SDItemButton.h"

@implementation SDItemButton

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = [UIFont systemFontOfSize:9];
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return self;
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    
    CGFloat x = contentRect.size.width*0.2;
    CGFloat y = contentRect.size.height*0.15;
    CGFloat w = contentRect.size.width - x * 2;
    CGRect rect = CGRectMake(x, y, w, w);
    return rect;
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    
    CGFloat y = CGRectGetMaxY(self.imageView.frame);
    CGRect rect = CGRectMake(0,y,contentRect.size.width, contentRect.size.height -y);
    return rect;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    [self setTitle:title forState:UIControlStateNormal];
}
-(void)setImageName:(NSString *)imageName{
    _imageName = imageName;
    [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
}

-(void)setTitleColor:(UIColor *)titleColor{
    [self setTitleColor:titleColor forState:UIControlStateNormal];
}



@end
